home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 352_01 / vecnorm.cpp < prev    next >
C/C++ Source or Header  |  1991-04-22  |  642b  |  32 lines

  1. // vecnorm.cpp - take norm (=sum of squares of elements) of vector
  2. //                 between 2 endpoints.
  3.  
  4. #include <stdlib.h>
  5. #include <alloc.h>
  6. #include <string.h>
  7. #include "wtwg.h"
  8.  
  9. #include "dblib.h"
  10.  
  11. #include "vector.h"
  12.  
  13.  
  14.     float norm (Vector& vec,  int n1, int n2 )
  15.     // norm between point1 and point2    (friend function of Vector)
  16.     // if point2 == -1, sums to end of V.
  17.         {
  18.         float s=0, xv;
  19.  
  20.         if ( n2<0 ) n2 = vec.n;
  21.         float *vv = vec.v;
  22.         for ( int i=n1; i<n2; ++i )
  23.             {
  24.             xv = vv[i];
  25.             s+= xv*xv;            // sum of squares.
  26.             }
  27.         return (s);
  28.  
  29.         }
  30.  
  31. //---------------------- end VECNORM.CPP ----------------------------
  32.